import http from "../../../../assets/js/http"

const name = "__EN_NAME__"

const create = function () {
    let entity = {}
    return {entity}
}


const find = function(id,func){
    http.get('/admin/' + name +'/info' ,{id},res=>{
        func(res)
    })
}
const findToEdit = function(id,func){
    http.get('/admin/' + name +'/' + id ,{},res=>{
        func(res)
    })
}

const findOne = function (param,func,index){
    if (index === undefined)index=0
    http.post('/admin/' + name +'/list',param,res=>{
        if (res.data.lists.length === 0){
            func(null)
        }else {
            func(res.data.lists[index])
        }
    })
}

const findBy = function (param,func) {
    http.post('/admin/' + name +'/list', param, res => {
        func(res.data.lists, res.data.query)
    })
}

const save = function (data,func){
    var action = "/update"
    if (data.id === undefined || data.id === 0){
        action = "/create"
    }

    http.post('/admin/' + name + action ,data,res=>{
        func(res)
    })
}
const remove = function (ids,func){
    http.post('/admin/' + name +'/delete',{ids},res=>{
        func(res)
    })
}
const copy = function (ids,func){
    http.post('/admin/' + name +'/copy',{ids},res=>{
        func(res)
    })
}

export default {name,create,find,findToEdit,findOne,findBy,remove,copy,save}

